package com.bluetane.utils;

public class UuidHash
{
    public static String uuidHash(String serviceName)
    {
        String startHash = "4ddfa2823e5e44569e90f03834fb09a9";
        String hash = "";
        int serviceCharValue;
        int startHashCharValue;
        if (serviceName == null || serviceName.equals(""))
            return null;
        for (int i=0; i<startHash.length();i++)
        {
            serviceCharValue = Character.getNumericValue(serviceName.charAt(i % serviceName.length())) + serviceName.length();
            startHashCharValue = Character.getNumericValue(startHash.charAt(i));
            hash = hash + Integer.toHexString((serviceCharValue + startHashCharValue) % 16);
        }
        return hash;
    }

    public static String uuidHashDash(String serviceName){
        String hash=uuidHash(serviceName);
        if(hash==null||hash.equals("")) return hash;

        StringBuilder builder= new StringBuilder(hash);
        builder.insert(20, "-");//8+4+4+4
        builder.insert(16, "-");//8+4+4
        builder.insert(12, "-");//8+4
        builder.insert(8, "-");//8
        return builder.toString();
    }

    private static void testHash(String input)
    {
        System.out.println(input+": "+uuidHashDash(input));
    }
    
    public static void main(String[] args)
    {
        testHash("Test");
        testHash("TestTest");
        testHash("Test2");
        testHash("Test3");
        testHash("Test4");
        testHash("SFDL");
        testHash("Hi");
        testHash("This is my super long name test test test test tesTest");
        testHash("");
        testHash("J");
        testHash(null);
        testHash("StudyBuddy");
    }
}